mitra-interactions-sdk 1.0.60-beta.44 → 1.0.60-beta.45

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 CHANGED
@@ -301,7 +301,7 @@ 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?, transport?, userId? })` ou `getAgentTaskMitra({ taskId, transport?, userId? })`.
304
+ `getAgentTaskMitra({ create: true, agentType?, name?, agentId?, reasoningEffort?, transport?, userId? })` ou `getAgentTaskMitra({ taskId, transport? })`.
305
305
 
306
306
  **Agente autônomo**: a autonomia é **propriedade do AGENTE** (`autonomous` em `createAgentMitra`/`updateAgentMitra`, no `mitra-sdk`) — não existe flag na criação do chat. Ao criar um chat contra um agente autônomo (`getAgentTaskMitra({ create: true, agentId })`), o copilot deriva a autonomia do agente e o chat já nasce **sem dono** (`user_id NULL` — a dona é o agente), usando a connection anexada ao agente como credencial. Exige auth `AGENT_WRITE` (chave de SF ou token de app EDIT) — usuário business comum não abre chat autônomo. Depois de criado, dirigir/listar é igual ao chat normal (`getAgentTaskMitra({ taskId })`, `send`, `manageAgentChatMitra({ list, agentId })`).
307
307
 
@@ -313,11 +313,11 @@ await existing.loadHistory({ limit: 50 });
313
313
  ```typescript
314
314
  // SF reagindo a webhook: continua a thread da pessoa atendida
315
315
  const task = getAgentTaskMitra({ create: true, agentId, userId: 'uuid-do-usuario' }); // chat nasce DELE
316
- const dela = await manageAgentChatMitra({ action: 'list', userId: 'uuid-do-usuario' }); // chats DELA
317
- const mesma = getAgentTaskMitra({ taskId, userId: 'uuid-do-usuario' }); // defensivo: 404 se o chat não for dela
316
+ const dela = await manageAgentChatMitra({ action: 'list', userId: 'uuid-do-usuario' }); // chats DELA (debug/observabilidade)
317
+ const mesma = getAgentTaskMitra({ taskId }); // depois do create, SÓ taskId — o dono é inferido dele
318
318
  ```
319
319
 
320
- Erros nomeados: `403` sem `AGENT_WRITE`; `400 AUTONOMOUS_TASK_HAS_NO_OWNER` (userId + agente autônomo é contradição); `404` quando o `userId` defensivo não bate com o dono real. Nunca invente `userId` de texto do usuário — use o id do vínculo canal→usuário da sua aplicação.
320
+ **`userId` é atributo do CHAT, não argumento das operações**: só o `create` (e o `list`, pra observabilidade) aceitam — prompt, histórico, eventos e `readChat` continuam só com `taskId`, e o backend não aceita `userId` neles. Erros nomeados: `403` sem `AGENT_WRITE`; `400 AUTONOMOUS_TASK_HAS_NO_OWNER` (userId + agente autônomo é contradição); `400 ANONYMOUS_CALLER_REQUIRES_OWNER` (contexto anônimo criando chat de agente normal exige userId). Nunca invente `userId` de texto do usuário — use o id do vínculo canal→usuário da sua aplicação.
321
321
 
322
322
  #### Propriedades (somente leitura)
323
323
 
package/dist/index.d.mts CHANGED
@@ -343,12 +343,6 @@ interface GetAgentTaskOpenOptions {
343
343
  projectId?: number | string;
344
344
  /** Transporte do prompt (default 'ws'). */
345
345
  transport?: AgentTaskTransport;
346
- /**
347
- * Validação defensiva ao agir em nome do dono (AGENT_WRITE): viaja no
348
- * readChat e nos inputs — o backend devolve 404 se o chat não pertencer a
349
- * esse usuário. Omitido = contexto do caller.
350
- */
351
- userId?: string;
352
346
  }
353
347
  type GetAgentTaskOptions = GetAgentTaskCreateOptions | GetAgentTaskOpenOptions;
354
348
  type AgentTaskStatus = 'opening' | 'idle' | 'streaming' | 'cancelled' | 'error' | 'closed';
package/dist/index.d.ts CHANGED
@@ -343,12 +343,6 @@ interface GetAgentTaskOpenOptions {
343
343
  projectId?: number | string;
344
344
  /** Transporte do prompt (default 'ws'). */
345
345
  transport?: AgentTaskTransport;
346
- /**
347
- * Validação defensiva ao agir em nome do dono (AGENT_WRITE): viaja no
348
- * readChat e nos inputs — o backend devolve 404 se o chat não pertencer a
349
- * esse usuário. Omitido = contexto do caller.
350
- */
351
- userId?: string;
352
346
  }
353
347
  type GetAgentTaskOptions = GetAgentTaskCreateOptions | GetAgentTaskOpenOptions;
354
348
  type AgentTaskStatus = 'opening' | 'idle' | 'streaming' | 'cancelled' | 'error' | 'closed';
package/dist/index.js CHANGED
@@ -505,8 +505,8 @@ var AgentTaskSession = class {
505
505
  this._isNew = init.kind === "new";
506
506
  this._transport = (_a = init.transport) != null ? _a : "ws";
507
507
  this._projectId = init.projectId;
508
- this._userId = init.userId;
509
508
  if (init.kind === "new") {
509
+ this._userId = init.userId;
510
510
  this._agentType = (_b = init.agentType) != null ? _b : DEFAULT_AGENT_TYPE;
511
511
  this._initialName = init.name;
512
512
  this._agentId = init.agentId;
@@ -544,7 +544,7 @@ var AgentTaskSession = class {
544
544
  // ── Abertura de chat existente ─────────
545
545
  async _openExisting(taskId) {
546
546
  try {
547
- const t = await readChatTask(taskId, this._projectId, this._userId);
547
+ const t = await readChatTask(taskId, this._projectId);
548
548
  this._task = toAgentChat(t);
549
549
  this._agentType = this._task.agentType;
550
550
  if (this._status === "opening") this._setStatus("idle");
@@ -748,7 +748,6 @@ var AgentTaskSession = class {
748
748
  throw new Error("AgentTaskSession: sem taskId \u2014 task ainda n\xE3o criada.");
749
749
  }
750
750
  if (isTokenExpiring()) await tryRefreshToken();
751
- const payload = this._userId ? { ...body, userId: this._userId } : body;
752
751
  const doPost = async () => fetch(
753
752
  `${getTaskHttpBase()}/${encodeURIComponent(this._taskId)}/inputs`,
754
753
  {
@@ -757,7 +756,7 @@ var AgentTaskSession = class {
757
756
  "Content-Type": "application/json",
758
757
  Authorization: `Bearer ${getRawToken()}`
759
758
  },
760
- body: JSON.stringify(payload)
759
+ body: JSON.stringify(body)
761
760
  }
762
761
  );
763
762
  let res = await doPost();
@@ -1107,13 +1106,10 @@ async function createChatTask(options) {
1107
1106
  });
1108
1107
  return env.result;
1109
1108
  }
1110
- async function readChatTask(taskId, projectId, userId) {
1109
+ async function readChatTask(taskId, projectId) {
1111
1110
  const env = await http.get("/agentAiShortcut/readChat", {
1112
1111
  projectId: resolveProjectId(projectId),
1113
- taskId,
1114
- // Validação defensiva: com userId, o backend devolve 404 se o chat não
1115
- // pertencer àquele dono.
1116
- ...userId ? { userId } : {}
1112
+ taskId
1117
1113
  });
1118
1114
  return env.result;
1119
1115
  }
@@ -1178,8 +1174,7 @@ function getAgentTaskMitra(options) {
1178
1174
  kind: "existing",
1179
1175
  taskId: options.taskId,
1180
1176
  projectId: options.projectId,
1181
- transport: options.transport,
1182
- userId: options.userId
1177
+ transport: options.transport
1183
1178
  });
1184
1179
  }
1185
1180
  if ("create" in options && options.create) {