mitra-interactions-sdk 1.0.60-beta.47 → 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 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?, transport?, userId? })` ou `getAgentTaskMitra({ taskId, transport? })`.
304
+ `getAgentTaskMitra({ create: true, agentType?, name?, agentId?, reasoningEffort?, autonomous?, userId?, transport? })` ou `getAgentTaskMitra({ taskId, transport? })`.
305
305
 
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 })`).
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
@@ -531,6 +531,7 @@ var AgentTaskSession = class {
531
531
  this._initialName = init.name;
532
532
  this._agentId = init.agentId;
533
533
  this._reasoningEffort = init.reasoningEffort;
534
+ this._autonomous = init.autonomous;
534
535
  this._status = "idle";
535
536
  } else {
536
537
  this._agentType = DEFAULT_AGENT_TYPE;
@@ -620,7 +621,8 @@ var AgentTaskSession = class {
620
621
  title: this._initialName,
621
622
  agentType: this._agentType,
622
623
  agentId: this._agentId,
623
- userId: this._userId
624
+ userId: this._userId,
625
+ autonomous: this._autonomous
624
626
  });
625
627
  this._task = toAgentChat(t);
626
628
  this._taskId = this._task.id;
@@ -1113,15 +1115,16 @@ async function createChatTask(options) {
1113
1115
  projectId: resolveProjectId(options.projectId),
1114
1116
  ...options.title ? { title: options.title } : {},
1115
1117
  agentType: options.agentType,
1116
- // Autonomia é propriedade do AGENTE (createAgentMitra/updateAgentMitra no
1117
- // mitra-sdk): o copilot deriva do agentId — o chat de agente autônomo já
1118
- // nasce ownerless sem flag nenhum aqui.
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.
1119
1121
  ...options.agentId ? { agentId: options.agentId } : {},
1122
+ ...options.autonomous ? { autonomous: true } : {},
1120
1123
  // Agir EM NOME do dono (SF/webhook/cron com AGENT_WRITE): o chat nasce
1121
1124
  // pertencendo a esse usuário; o turno roda com a identidade/credencial
1122
1125
  // DELE. Ausente = chat do caller, byte a byte como sempre.
1123
1126
  // Erros do backend passam crus: 403 (sem AGENT_WRITE),
1124
- // 400 AUTONOMOUS_TASK_HAS_NO_OWNER (userId + agente autônomo é contradição).
1127
+ // 400 AUTONOMOUS_TASK_HAS_NO_OWNER (userId + autonomous é contradição).
1125
1128
  ...options.userId ? { userId: options.userId } : {}
1126
1129
  });
1127
1130
  return env.result;
@@ -1198,6 +1201,9 @@ function getAgentTaskMitra(options) {
1198
1201
  });
1199
1202
  }
1200
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
+ }
1201
1207
  return new AgentTaskSession({
1202
1208
  kind: "new",
1203
1209
  projectId: options.projectId,
@@ -1206,7 +1212,8 @@ function getAgentTaskMitra(options) {
1206
1212
  agentId: options.agentId,
1207
1213
  transport: options.transport,
1208
1214
  reasoningEffort: options.reasoningEffort,
1209
- userId: options.userId
1215
+ userId: options.userId,
1216
+ autonomous: options.autonomous
1210
1217
  });
1211
1218
  }
1212
1219
  throw new Error("getAgentTaskMitra: passe { create: true } ou { taskId }.");