mitra-interactions-sdk 1.0.60-beta.46 → 1.0.60-beta.48
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 -2
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +34 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +52 -52
package/README.md
CHANGED
|
@@ -301,9 +301,9 @@ const existing = getAgentTaskMitra({ taskId: 'uuid-da-task' });
|
|
|
301
301
|
await existing.loadHistory({ limit: 50 });
|
|
302
302
|
```
|
|
303
303
|
|
|
304
|
-
`getAgentTaskMitra({ create: true, agentType?, name?, agentId?, reasoningEffort?,
|
|
304
|
+
`getAgentTaskMitra({ create: true, agentType?, name?, agentId?, reasoningEffort?, autonomous?, userId?, transport? })` ou `getAgentTaskMitra({ taskId, transport? })`.
|
|
305
305
|
|
|
306
|
-
**
|
|
306
|
+
**Chat autônomo (`autonomous: true`)**: cria o chat **sem dono** (`user_id NULL` — a dona é o agente), pra Server Function/webhook/cron dirigir o agente. A autonomia é **propriedade do CHAT** — o flag `autonomous` do agente não tem mais leitor no backend. Exige `agentId` (fail-fast no client) e o agente precisa ter uma **connection anexada** como credencial (senão `400 AUTONOMOUS_TASK_REQUIRES_CONNECTION`); auth `AGENT_WRITE` (chave de SF ou token de app EDIT), senão 403. Depois de criado, dirigir/listar é igual ao chat normal (`getAgentTaskMitra({ taskId })`, `send`, `manageAgentChatMitra({ list, agentId })`). Sem o flag, comportamento de sempre (chat com dono = o caller).
|
|
307
307
|
|
|
308
308
|
- `agentType` vem de `manageAgentCredentialMitra({ action: 'list_models' })` — ex.: `'ANTHROPIC_CLAUDE_OPUS'`, `'OPENAI_GPT5'`. Default: `'ANTHROPIC_CLAUDE_OPUS'`.
|
|
309
309
|
- **`agentId`**: id de um agente business (CRUD via `mitra-sdk`: `listAgentsMitra` e família). A sessão sobe com o system prompt do agente e um token escopado — as tools enxergam só as Server Functions dele. **Sem `agentId`: sessão business sem agente** — sem system prompt e sem acesso às Server Functions (as tools recusam); não há adoção automática de agente único. Na prática, sempre passe `agentId`.
|
package/dist/index.d.mts
CHANGED
|
@@ -333,6 +333,17 @@ interface GetAgentTaskCreateOptions {
|
|
|
333
333
|
* ela age.
|
|
334
334
|
*/
|
|
335
335
|
userId?: string;
|
|
336
|
+
/**
|
|
337
|
+
* Cria o chat SEM dono (user_id NULL — a dona é o agente): a modalidade
|
|
338
|
+
* AUTÔNOMA, onde uma Server Function / webhook / cron dirige o agente.
|
|
339
|
+
* Exige `agentId` e o agente precisa ter uma connection anexada (é a
|
|
340
|
+
* credencial do chat); auth AGENT_WRITE (chave de SF), senão 403. Agente
|
|
341
|
+
* sem connection: 400 AUTONOMOUS_TASK_REQUIRES_CONNECTION. Mutuamente
|
|
342
|
+
* exclusivo com `userId` (400 AUTONOMOUS_TASK_HAS_NO_OWNER).
|
|
343
|
+
* Omitido = chat com dono (o caller), comportamento de sempre.
|
|
344
|
+
* A autonomia é do CHAT: o flag `autonomous` do AGENTE não tem leitor.
|
|
345
|
+
*/
|
|
346
|
+
autonomous?: boolean;
|
|
336
347
|
/** Transporte do prompt (default 'ws'). */
|
|
337
348
|
transport?: AgentTaskTransport;
|
|
338
349
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -333,6 +333,17 @@ interface GetAgentTaskCreateOptions {
|
|
|
333
333
|
* ela age.
|
|
334
334
|
*/
|
|
335
335
|
userId?: string;
|
|
336
|
+
/**
|
|
337
|
+
* Cria o chat SEM dono (user_id NULL — a dona é o agente): a modalidade
|
|
338
|
+
* AUTÔNOMA, onde uma Server Function / webhook / cron dirige o agente.
|
|
339
|
+
* Exige `agentId` e o agente precisa ter uma connection anexada (é a
|
|
340
|
+
* credencial do chat); auth AGENT_WRITE (chave de SF), senão 403. Agente
|
|
341
|
+
* sem connection: 400 AUTONOMOUS_TASK_REQUIRES_CONNECTION. Mutuamente
|
|
342
|
+
* exclusivo com `userId` (400 AUTONOMOUS_TASK_HAS_NO_OWNER).
|
|
343
|
+
* Omitido = chat com dono (o caller), comportamento de sempre.
|
|
344
|
+
* A autonomia é do CHAT: o flag `autonomous` do AGENTE não tem leitor.
|
|
345
|
+
*/
|
|
346
|
+
autonomous?: boolean;
|
|
336
347
|
/** Transporte do prompt (default 'ws'). */
|
|
337
348
|
transport?: AgentTaskTransport;
|
|
338
349
|
}
|
package/dist/index.js
CHANGED
|
@@ -64,13 +64,31 @@ var POPUP_W = 480;
|
|
|
64
64
|
var POPUP_H = 600;
|
|
65
65
|
var POPUP_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
66
66
|
var SSO_AUTH_PAGE_URL = "https://beta.infusion.cloud/sdk-auth.html";
|
|
67
|
-
async function fetchSsoAuthPageUrl(
|
|
67
|
+
async function fetchSsoAuthPageUrl(baseURL, projectId) {
|
|
68
68
|
const config = isConfigured() ? getConfig() : null;
|
|
69
69
|
if (config == null ? void 0 : config.authPageUrl) return config.authPageUrl;
|
|
70
|
+
const discovered = await discoverSsoAuthPageUrl(baseURL, projectId);
|
|
71
|
+
if (discovered) return discovered;
|
|
70
72
|
const injected = readInjectedEnv().authPageUrl;
|
|
71
73
|
if (injected) return injected;
|
|
72
74
|
return SSO_AUTH_PAGE_URL;
|
|
73
75
|
}
|
|
76
|
+
async function discoverSsoAuthPageUrl(baseURL, projectId) {
|
|
77
|
+
if (!baseURL || !projectId) return null;
|
|
78
|
+
try {
|
|
79
|
+
const path = `/sso/config?projectId=${encodeURIComponent(projectId)}`;
|
|
80
|
+
const response = await getFetch()(buildBffAuthEndpoint(baseURL, path), {
|
|
81
|
+
method: "GET",
|
|
82
|
+
headers: { accept: "application/json" }
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok) return null;
|
|
85
|
+
const data = await response.json().catch(() => null);
|
|
86
|
+
const url = data && typeof data.authPageUrl === "string" ? data.authPageUrl : "";
|
|
87
|
+
return url || null;
|
|
88
|
+
} catch (e) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
74
92
|
var SSO_ENABLED_PROVIDERS = ["google", "microsoft"];
|
|
75
93
|
function providerLabel(provider) {
|
|
76
94
|
return provider === "microsoft" ? "Microsoft" : provider === "google" ? "Google" : provider;
|
|
@@ -226,7 +244,7 @@ async function loginWithProvider(provider, options) {
|
|
|
226
244
|
const { authUrl, projectId } = resolveLoginOptions(options);
|
|
227
245
|
const state = generateState();
|
|
228
246
|
const appId = String(projectId);
|
|
229
|
-
const authPageUrl = await fetchSsoAuthPageUrl(authUrl);
|
|
247
|
+
const authPageUrl = await fetchSsoAuthPageUrl(authUrl, appId);
|
|
230
248
|
const pageOrigin = getOriginFromUrl(authPageUrl);
|
|
231
249
|
const redirectUri = stripToOriginPath(authPageUrl);
|
|
232
250
|
const startUrl = buildStartUrl(authPageUrl, provider, state, appId, authUrl);
|
|
@@ -250,7 +268,7 @@ async function startSsoRedirect(provider, options) {
|
|
|
250
268
|
const { authUrl, projectId } = resolveLoginOptions(options);
|
|
251
269
|
const state = generateState();
|
|
252
270
|
const appId = String(projectId);
|
|
253
|
-
const authPageUrl = await fetchSsoAuthPageUrl();
|
|
271
|
+
const authPageUrl = await fetchSsoAuthPageUrl(authUrl, appId);
|
|
254
272
|
const redirectUri = stripToOriginPath(authPageUrl);
|
|
255
273
|
persistRedirectContext({
|
|
256
274
|
state,
|
|
@@ -513,6 +531,7 @@ var AgentTaskSession = class {
|
|
|
513
531
|
this._initialName = init.name;
|
|
514
532
|
this._agentId = init.agentId;
|
|
515
533
|
this._reasoningEffort = init.reasoningEffort;
|
|
534
|
+
this._autonomous = init.autonomous;
|
|
516
535
|
this._status = "idle";
|
|
517
536
|
} else {
|
|
518
537
|
this._agentType = DEFAULT_AGENT_TYPE;
|
|
@@ -602,7 +621,8 @@ var AgentTaskSession = class {
|
|
|
602
621
|
title: this._initialName,
|
|
603
622
|
agentType: this._agentType,
|
|
604
623
|
agentId: this._agentId,
|
|
605
|
-
userId: this._userId
|
|
624
|
+
userId: this._userId,
|
|
625
|
+
autonomous: this._autonomous
|
|
606
626
|
});
|
|
607
627
|
this._task = toAgentChat(t);
|
|
608
628
|
this._taskId = this._task.id;
|
|
@@ -1095,15 +1115,16 @@ async function createChatTask(options) {
|
|
|
1095
1115
|
projectId: resolveProjectId(options.projectId),
|
|
1096
1116
|
...options.title ? { title: options.title } : {},
|
|
1097
1117
|
agentType: options.agentType,
|
|
1098
|
-
// Autonomia é propriedade do
|
|
1099
|
-
//
|
|
1100
|
-
//
|
|
1118
|
+
// Autonomia é propriedade do CHAT: autonomous: true cria a task SEM dono
|
|
1119
|
+
// (a dona é o agente; exige connection anexada e AGENT_WRITE). O flag no
|
|
1120
|
+
// AGENTE não tem mais leitor no backend.
|
|
1101
1121
|
...options.agentId ? { agentId: options.agentId } : {},
|
|
1122
|
+
...options.autonomous ? { autonomous: true } : {},
|
|
1102
1123
|
// Agir EM NOME do dono (SF/webhook/cron com AGENT_WRITE): o chat nasce
|
|
1103
1124
|
// pertencendo a esse usuário; o turno roda com a identidade/credencial
|
|
1104
1125
|
// DELE. Ausente = chat do caller, byte a byte como sempre.
|
|
1105
1126
|
// Erros do backend passam crus: 403 (sem AGENT_WRITE),
|
|
1106
|
-
// 400 AUTONOMOUS_TASK_HAS_NO_OWNER (userId +
|
|
1127
|
+
// 400 AUTONOMOUS_TASK_HAS_NO_OWNER (userId + autonomous é contradição).
|
|
1107
1128
|
...options.userId ? { userId: options.userId } : {}
|
|
1108
1129
|
});
|
|
1109
1130
|
return env.result;
|
|
@@ -1180,6 +1201,9 @@ function getAgentTaskMitra(options) {
|
|
|
1180
1201
|
});
|
|
1181
1202
|
}
|
|
1182
1203
|
if ("create" in options && options.create) {
|
|
1204
|
+
if (options.autonomous && !options.agentId) {
|
|
1205
|
+
throw new Error("getAgentTaskMitra: autonomous exige agentId \u2014 o chat aut\xF4nomo pertence ao agente (e o agente precisa ter uma connection anexada).");
|
|
1206
|
+
}
|
|
1183
1207
|
return new AgentTaskSession({
|
|
1184
1208
|
kind: "new",
|
|
1185
1209
|
projectId: options.projectId,
|
|
@@ -1188,7 +1212,8 @@ function getAgentTaskMitra(options) {
|
|
|
1188
1212
|
agentId: options.agentId,
|
|
1189
1213
|
transport: options.transport,
|
|
1190
1214
|
reasoningEffort: options.reasoningEffort,
|
|
1191
|
-
userId: options.userId
|
|
1215
|
+
userId: options.userId,
|
|
1216
|
+
autonomous: options.autonomous
|
|
1192
1217
|
});
|
|
1193
1218
|
}
|
|
1194
1219
|
throw new Error("getAgentTaskMitra: passe { create: true } ou { taskId }.");
|