intella-cli 0.0.4 → 0.0.6

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.
Files changed (2) hide show
  1. package/bin/intella.js +230 -38
  2. package/package.json +1 -1
package/bin/intella.js CHANGED
@@ -251782,7 +251782,7 @@ class ClaudeAgent extends BaseAgent {
251782
251782
  const customProvider = createClaudeCode({
251783
251783
  defaultSettings: settings
251784
251784
  });
251785
- this.modelInstance = customProvider(modelId);
251785
+ this.modelInstance = customProvider(modelId, settings);
251786
251786
  } else {
251787
251787
  this.modelInstance = claudeCode(modelId);
251788
251788
  }
@@ -251810,10 +251810,19 @@ class CodexAgent extends BaseAgent {
251810
251810
  this.modelInstance = codexCli2(modelId, {
251811
251811
  reasoningEffort: this.config.reasoningEffort,
251812
251812
  approvalMode: this.config.approvalMode,
251813
- sandboxMode: this.config.sandboxMode,
251813
+ sandboxMode: this.config.sandboxMode || "workspace-write",
251814
251814
  mcpServers: this.config.mcpServers,
251815
251815
  verbose: this.config.verbose,
251816
- logger: this.config.logger
251816
+ logger: this.config.logger,
251817
+ dangerouslyBypassApprovalsAndSandbox: this.config.dangerouslyBypassApprovalsAndSandbox,
251818
+ allowNpx: this.config.allowNpx,
251819
+ cwd: this.config.cwd,
251820
+ fullAuto: this.config.fullAuto || true,
251821
+ webSearch: this.config.webSearch || true,
251822
+ configOverrides: {
251823
+ sandbox_workspace_write: { network_access: true },
251824
+ ...this.config.configOverrides || {}
251825
+ }
251817
251826
  });
251818
251827
  } else {
251819
251828
  this.modelInstance = codexCli2(modelId);
@@ -253784,7 +253793,13 @@ class OpenCodeAgent extends BaseAgent {
253784
253793
  async getModel() {
253785
253794
  if (!this.modelInstance) {
253786
253795
  const modelId = this.config.model || "anthropic/claude-sonnet-4-5-20250929";
253787
- this.modelInstance = opencode(modelId);
253796
+ console.log("modelId", modelId);
253797
+ console.log("cwd", this.config.cwd);
253798
+ this.modelInstance = opencode(modelId, {
253799
+ cwd: this.config.cwd,
253800
+ verbose: this.config.verbose,
253801
+ tools: this.config.tools
253802
+ });
253788
253803
  }
253789
253804
  return this.modelInstance;
253790
253805
  }
@@ -306235,8 +306250,8 @@ var import_ulid_uuid_converter = __toESM(require_dist8(), 1);
306235
306250
 
306236
306251
  class IdGenerator {
306237
306252
  static ulid = monotonicFactory();
306238
- static generateIds() {
306239
- const ulid4 = this.ulid();
306253
+ static generateIds(timestamp) {
306254
+ const ulid4 = this.ulid(timestamp);
306240
306255
  const uuid5 = this.ulidToUuid(ulid4);
306241
306256
  return [ulid4, uuid5];
306242
306257
  }
@@ -306363,6 +306378,7 @@ async function publishChunkToSession(sessionId, chunk, redisUrl) {
306363
306378
  chunkId,
306364
306379
  chunk: chunk.chunk || "",
306365
306380
  segmentId: chunk.segmentId || "",
306381
+ parentSegmentId: chunk.parentSegmentId || "",
306366
306382
  isDone: chunk.isDone ? "true" : "false",
306367
306383
  type: chunk.type || "text-delta",
306368
306384
  senderType: chunk.senderType || "",
@@ -306680,15 +306696,13 @@ import { existsSync as existsSync8, readFileSync as readFileSync8, writeFileSync
306680
306696
  init_config();
306681
306697
  async function getUserInfo() {
306682
306698
  try {
306683
- const token = await getAccessToken();
306684
- if (!token) {
306699
+ const authHeaders = await getAuthHeaders();
306700
+ if (!authHeaders || Object.keys(authHeaders).length === 0) {
306685
306701
  return null;
306686
306702
  }
306687
306703
  const config4 = getConfig();
306688
306704
  const response = await fetch(`${config4.apiUrl}/api/v1/auth/me`, {
306689
- headers: {
306690
- Authorization: `Bearer ${token}`
306691
- }
306705
+ headers: authHeaders
306692
306706
  });
306693
306707
  if (response.ok) {
306694
306708
  return await response.json();
@@ -306721,6 +306735,25 @@ async function refreshToken(refreshToken2) {
306721
306735
  return null;
306722
306736
  }
306723
306737
  }
306738
+ async function getOrCreateApiKey(accessToken) {
306739
+ try {
306740
+ const config4 = getConfig();
306741
+ const apiKeyUrl = `${config4.apiUrl}/api/v1/auth/api-key`;
306742
+ const response = await fetch(apiKeyUrl, {
306743
+ method: "GET",
306744
+ headers: {
306745
+ Authorization: `Bearer ${accessToken}`
306746
+ }
306747
+ });
306748
+ if (!response.ok) {
306749
+ return null;
306750
+ }
306751
+ const data = await response.json();
306752
+ return data.api_key || null;
306753
+ } catch (error49) {
306754
+ return null;
306755
+ }
306756
+ }
306724
306757
 
306725
306758
  // auth.ts
306726
306759
  function getAuth() {
@@ -306755,7 +306788,7 @@ function clearAuth() {
306755
306788
  }
306756
306789
  }
306757
306790
  }
306758
- async function getAccessToken() {
306791
+ async function getAccessToken2() {
306759
306792
  const auth = getAuth();
306760
306793
  if (!auth) {
306761
306794
  return null;
@@ -306790,13 +306823,68 @@ async function getAccessToken() {
306790
306823
  }
306791
306824
  return null;
306792
306825
  }
306826
+ async function getAuthHeaders() {
306827
+ const auth = getAuth();
306828
+ if (!auth) {
306829
+ return {};
306830
+ }
306831
+ if (auth.type === "apikey") {
306832
+ const envApiKey = process.env.INTELLA_API_KEY;
306833
+ const apiKey = envApiKey || auth.apikey;
306834
+ if (apiKey) {
306835
+ return {
306836
+ "X-API-Key": apiKey
306837
+ };
306838
+ }
306839
+ if (auth.oauth?.refresh_token) {
306840
+ const newApiKey = await refreshApiKeyFromRefreshToken(auth.oauth.refresh_token);
306841
+ if (newApiKey) {
306842
+ saveAuth({
306843
+ type: "apikey",
306844
+ apikey: newApiKey,
306845
+ oauth: auth.oauth
306846
+ });
306847
+ return {
306848
+ "X-API-Key": newApiKey
306849
+ };
306850
+ }
306851
+ }
306852
+ return {};
306853
+ }
306854
+ if (auth.type === "oauth" && auth.oauth) {
306855
+ const token = await getAccessToken2();
306856
+ if (token) {
306857
+ return {
306858
+ Authorization: `Bearer ${token}`
306859
+ };
306860
+ }
306861
+ }
306862
+ return {};
306863
+ }
306864
+ async function refreshApiKeyFromRefreshToken(refreshTokenValue) {
306865
+ try {
306866
+ const tokenData = await refreshToken(refreshTokenValue);
306867
+ if (!tokenData || !tokenData.access_token) {
306868
+ return null;
306869
+ }
306870
+ const apiKey = await getOrCreateApiKey(tokenData.access_token);
306871
+ return apiKey;
306872
+ } catch (error49) {
306873
+ return null;
306874
+ }
306875
+ }
306793
306876
  function setAuthType(type) {
306794
306877
  const auth = getAuth() || { type };
306795
306878
  if (type === "apikey") {
306796
306879
  const envApiKey = process.env.INTELLA_API_KEY;
306797
306880
  saveAuth({
306798
306881
  type: "apikey",
306799
- apikey: envApiKey || auth.apikey
306882
+ apikey: envApiKey || auth.apikey,
306883
+ oauth: auth.oauth ? {
306884
+ refresh_token: auth.oauth.refresh_token,
306885
+ access_token: "",
306886
+ expires_at: 0
306887
+ } : undefined
306800
306888
  });
306801
306889
  } else {
306802
306890
  saveAuth({
@@ -306825,13 +306913,11 @@ async function publishSessionEvent(sessionId, event) {
306825
306913
  const config4 = getConfig();
306826
306914
  const apiUrl = config4.apiUrl || "https://app.intella.xyz";
306827
306915
  const endpoint = `${apiUrl}/api/v1/sessions/${sessionId}/events`;
306828
- const token = await getAccessToken();
306916
+ const authHeaders = await getAuthHeaders();
306829
306917
  const headers = {
306830
- "Content-Type": "application/json"
306918
+ "Content-Type": "application/json",
306919
+ ...authHeaders
306831
306920
  };
306832
- if (token) {
306833
- headers["Authorization"] = `Bearer ${token}`;
306834
- }
306835
306921
  try {
306836
306922
  const response = await fetch(endpoint, {
306837
306923
  method: "POST",
@@ -307044,7 +307130,11 @@ async function processAgentCommand(options, logger, doneCallback) {
307044
307130
  if (!agentConfig.executablePath) {
307045
307131
  agentConfig.executablePath = findClaudeBinary() || "/usr/local/bin/claude";
307046
307132
  }
307047
- agentConfig.allowedTools = ["Read", "Write", "Edit", "Bash", "WebSearch", "Grep"];
307133
+ agentConfig.allowedTools = ["Read", "Write", "Edit", "Bash", "WebSearch", "Grep", "WebFetch"];
307134
+ }
307135
+ if (agentType === "codex") {
307136
+ agentConfig.sandboxMode = "workspace-write";
307137
+ agentConfig.dangerouslyBypassApprovalsAndSandbox = true;
307048
307138
  }
307049
307139
  agentConfig.model = model;
307050
307140
  log.info(`[DAEMON] Executing agent task with agent: ${agentType}`);
@@ -307060,30 +307150,89 @@ async function processAgentCommand(options, logger, doneCallback) {
307060
307150
  let fullResponse = "";
307061
307151
  const responseChunks = [];
307062
307152
  let chunkCount = 0;
307063
- let segmentId = IdGenerator.generatePrefixUlid("seg");
307064
- let segmentSent = false;
307153
+ let mainSegmentId = IdGenerator.generatePrefixUlid("seg");
307154
+ let firstTextChunkSent = false;
307155
+ const isToolRelatedChunk = (type) => {
307156
+ return type.startsWith("tool-") || type === "tool-call" || type === "tool-result" || type === "tool-error" || type === "tool-input-start" || type === "tool-input-end" || type === "tool-input-delta" || type === "tool-output-denied";
307157
+ };
307158
+ const shouldEmitEvent = (chunk) => {
307159
+ if (chunk.isDone || chunk.type === "done" || chunk.type === "error" || chunk.type === "start") {
307160
+ return true;
307161
+ }
307162
+ return false;
307163
+ };
307164
+ const config4 = getConfig();
307165
+ let uniquePartId = {};
307166
+ let textSegment = [];
307065
307167
  for await (const chunk of sdk.streamTask(taskRequest, agentType)) {
307066
307168
  chunkCount++;
307067
307169
  responseChunks.push({ ...chunk, timestamp: Date.now() });
307170
+ const chunkData = chunk.data;
307171
+ if (chunkData && chunkData.id || chunkData?.toolCallId) {
307172
+ if (chunk.type === "text-start") {
307173
+ if (!uniquePartId[chunkData.id]) {
307174
+ if (textSegment.length > 0) {
307175
+ uniquePartId[chunkData.id] = IdGenerator.generatePrefixUlid("seg");
307176
+ textSegment.push(chunkData.id);
307177
+ } else {
307178
+ uniquePartId[chunkData.id] = mainSegmentId;
307179
+ textSegment.push(chunkData.id);
307180
+ }
307181
+ }
307182
+ } else if (chunk.type === "reasoning-start") {
307183
+ if (!uniquePartId[chunkData.id]) {
307184
+ uniquePartId[chunkData.id] = IdGenerator.generatePrefixUlid("seg");
307185
+ }
307186
+ } else if (chunk.type === "tool-input-start") {
307187
+ if (!uniquePartId[chunkData.id]) {
307188
+ uniquePartId[chunkData.id] = IdGenerator.generatePrefixUlid("seg");
307189
+ }
307190
+ }
307191
+ }
307068
307192
  if (session?.id) {
307069
- const config4 = getConfig();
307193
+ let currentSegmentId;
307194
+ if (chunk.type === "text-delta" || chunk.type === "text-start" || chunk.type === "text-end") {
307195
+ currentSegmentId = uniquePartId[chunkData.id];
307196
+ } else if (isToolRelatedChunk(chunk.type)) {
307197
+ if (chunkData.toolCallId) {
307198
+ currentSegmentId = uniquePartId[chunkData.toolCallId];
307199
+ } else if (chunkData.id) {
307200
+ currentSegmentId = uniquePartId[chunkData.id];
307201
+ } else {
307202
+ currentSegmentId = IdGenerator.generatePrefixUlid("seg");
307203
+ }
307204
+ } else if (chunk.type.startsWith("reasoning")) {
307205
+ if (chunkData.id) {
307206
+ currentSegmentId = uniquePartId[chunkData.id];
307207
+ } else {
307208
+ currentSegmentId = mainSegmentId;
307209
+ }
307210
+ } else if (chunk.type === "file") {
307211
+ currentSegmentId = IdGenerator.generatePrefixUlid("seg");
307212
+ } else {
307213
+ currentSegmentId = mainSegmentId;
307214
+ }
307070
307215
  await publishChunkToSession(session.id, {
307071
307216
  chunk: chunk.text,
307072
307217
  isDone: chunk.isDone,
307073
307218
  type: chunk.type,
307074
307219
  senderType: "assistant",
307075
307220
  timestamp: Date.now(),
307076
- segmentId,
307221
+ segmentId: currentSegmentId,
307222
+ parentSegmentId: mainSegmentId,
307077
307223
  data: {
307078
307224
  agentType,
307079
307225
  ...chunk.data
307080
307226
  }
307081
307227
  }, config4.redisUrl);
307082
- agentResponseEmitter.emit("agent:response", {
307083
- chunk,
307084
- sessionId: session.id,
307085
- segmentId
307086
- });
307228
+ if (shouldEmitEvent(chunk)) {
307229
+ agentResponseEmitter.emit("agent:response", {
307230
+ chunk,
307231
+ sessionId: session.id,
307232
+ segmentId: currentSegmentId,
307233
+ parentSegmentId: mainSegmentId
307234
+ });
307235
+ }
307087
307236
  if (options.streamAgentResult) {
307088
307237
  await publishChunk(options.sandboxId, {
307089
307238
  chunk: chunk.text,
@@ -307091,17 +307240,14 @@ async function processAgentCommand(options, logger, doneCallback) {
307091
307240
  type: chunk.type,
307092
307241
  senderType: "assistant",
307093
307242
  timestamp: Date.now(),
307094
- segmentId,
307243
+ segmentId: currentSegmentId,
307244
+ parentSegmentId: mainSegmentId,
307095
307245
  data: {
307096
307246
  agentType,
307097
307247
  ...chunk.data
307098
307248
  }
307099
307249
  });
307100
307250
  }
307101
- if (!segmentSent) {
307102
- }
307103
- } else if (chunk.type === "text-delta") {
307104
- process.stdout.write(chunk.text);
307105
307251
  }
307106
307252
  if (chunk.isDone) {
307107
307253
  log.info(`[DAEMON] \u2705 Agent execution completed (${chunkCount} chunks, ${fullResponse.length} chars)`);
@@ -307141,8 +307287,35 @@ async function processAgentCommand(options, logger, doneCallback) {
307141
307287
  }
307142
307288
  var agentResponseEmitter = new EventEmitter;
307143
307289
  agentResponseEmitter.on("agent:response", async (response) => {
307144
- console.log("Agent response:", response);
307145
- await publishSessionEvent(response.sessionId, response.chunk);
307290
+ let eventType = "chunk";
307291
+ if (response.chunk.isDone || response.chunk.type === "done") {
307292
+ eventType = "done";
307293
+ } else if (response.chunk.type === "error") {
307294
+ eventType = "error";
307295
+ } else if (response.chunk.type.startsWith("tool")) {
307296
+ eventType = "tool-use";
307297
+ } else if (response.chunk.type.startsWith("start")) {
307298
+ eventType = "start";
307299
+ } else if (response.chunk.type.startsWith("status")) {
307300
+ eventType = "status";
307301
+ } else if (response.chunk.type.startsWith("thinking")) {
307302
+ eventType = "thinking";
307303
+ } else if (response.chunk.type.startsWith("attachments") || response.chunk.type.startsWith("file")) {
307304
+ eventType = "attachments";
307305
+ } else if (response.chunk.type.startsWith("finish")) {
307306
+ eventType = "finish-step";
307307
+ }
307308
+ await publishSessionEvent(response.sessionId, {
307309
+ type: eventType,
307310
+ segmentId: response.segmentId,
307311
+ parentSegmentId: response.parentSegmentId,
307312
+ message: response.chunk.text || eventType,
307313
+ data: {
307314
+ ...response.chunk,
307315
+ segmentId: response.segmentId,
307316
+ parentSegmentId: response.parentSegmentId
307317
+ }
307318
+ });
307146
307319
  });
307147
307320
 
307148
307321
  // commands/sandbox.ts
@@ -307934,7 +308107,7 @@ async function loginCommand(options) {
307934
308107
  reject(new Error("Authentication timeout. Please try again."));
307935
308108
  }
307936
308109
  }, timeout);
307937
- listenToSSE(sseUrl, (data) => {
308110
+ listenToSSE(sseUrl, async (data) => {
307938
308111
  if (resolved)
307939
308112
  return;
307940
308113
  if (data.type === "auth_success") {
@@ -307950,7 +308123,26 @@ async function loginCommand(options) {
307950
308123
  }
307951
308124
  });
307952
308125
  console.log("\u2705 Authentication successful!");
307953
- console.log(` Access token stored securely in ${config4.authPath}\n`);
308126
+ console.log(" Fetching API key for persistent authentication...");
308127
+ const apiKey = await getOrCreateApiKey(data.access_token);
308128
+ if (apiKey) {
308129
+ saveAuth({
308130
+ type: "apikey",
308131
+ apikey: apiKey,
308132
+ oauth: {
308133
+ refresh_token: data.refresh_token || "",
308134
+ access_token: "",
308135
+ expires_at: 0
308136
+ }
308137
+ });
308138
+ console.log("\u2705 API key stored successfully!");
308139
+ console.log(` You can now authenticate without worrying about token expiration.`);
308140
+ console.log(` Refresh token saved as fallback in case API key is deleted.`);
308141
+ console.log(` Credentials stored securely in ${config4.authPath}\n`);
308142
+ } else {
308143
+ console.log("\u26A0\uFE0F Warning: Could not fetch API key, using OAuth tokens (may expire)");
308144
+ console.log(` Access token stored securely in ${config4.authPath}\n`);
308145
+ }
307954
308146
  resolve8();
307955
308147
  } else if (data.type === "auth_error") {
307956
308148
  clearTimeout(timeoutId);
@@ -309166,4 +309358,4 @@ yargs_default(hideBin(process.argv)).scriptName("intella-cli").version("1.0.0").
309166
309358
  await whoamiCommand();
309167
309359
  }).demandCommand(1, "You need at least one command before moving on").help().alias("help", "h").alias("version", "v").strict().parse();
309168
309360
 
309169
- //# debugId=035B99541C02033564756E2164756E21
309361
+ //# debugId=83DEEA96E1B6BF6164756E2164756E21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intella-cli",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "bin": {
5
5
  "intella": "bin/intella.js"
6
6
  },