@contractspec/module.ai-chat 4.3.6 → 4.3.10

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 (46) hide show
  1. package/README.md +62 -370
  2. package/dist/adapters/ai-sdk-bundle-adapter.d.ts +1 -1
  3. package/dist/adapters/index.d.ts +1 -1
  4. package/dist/browser/context/index.js +93 -93
  5. package/dist/browser/core/index.js +308 -307
  6. package/dist/browser/index.js +3803 -3801
  7. package/dist/browser/presentation/components/index.js +2617 -2618
  8. package/dist/browser/presentation/hooks/index.js +476 -476
  9. package/dist/browser/presentation/index.js +2474 -2475
  10. package/dist/browser/providers/index.js +7 -7
  11. package/dist/context/index.d.ts +1 -1
  12. package/dist/context/index.js +93 -93
  13. package/dist/core/agent-tools-adapter.d.ts +1 -1
  14. package/dist/core/chat-service.d.ts +4 -4
  15. package/dist/core/create-chat-route.d.ts +1 -1
  16. package/dist/core/create-completion-route.d.ts +15 -0
  17. package/dist/core/export-formatters.d.ts +1 -1
  18. package/dist/core/index.d.ts +6 -6
  19. package/dist/core/index.js +308 -307
  20. package/dist/core/local-storage-conversation-store.d.ts +1 -1
  21. package/dist/core/surface-planner-tools.d.ts +2 -2
  22. package/dist/core/workflow-tools.d.ts +1 -1
  23. package/dist/index.d.ts +8 -8
  24. package/dist/index.js +3803 -3801
  25. package/dist/node/context/index.js +93 -93
  26. package/dist/node/core/index.js +308 -307
  27. package/dist/node/index.js +3803 -3801
  28. package/dist/node/presentation/components/index.js +2617 -2618
  29. package/dist/node/presentation/hooks/index.js +476 -476
  30. package/dist/node/presentation/index.js +2474 -2475
  31. package/dist/node/providers/index.js +7 -7
  32. package/dist/presentation/components/ChainOfThought.d.ts +1 -1
  33. package/dist/presentation/components/ChatExportToolbar.d.ts +1 -1
  34. package/dist/presentation/components/ChatSidebar.d.ts +1 -1
  35. package/dist/presentation/components/ChatWithExport.d.ts +1 -1
  36. package/dist/presentation/components/index.d.ts +11 -11
  37. package/dist/presentation/components/index.js +2617 -2618
  38. package/dist/presentation/hooks/index.d.ts +4 -4
  39. package/dist/presentation/hooks/index.js +476 -476
  40. package/dist/presentation/hooks/useChat.d.ts +6 -6
  41. package/dist/presentation/hooks/useConversations.d.ts +1 -1
  42. package/dist/presentation/hooks/useProviders.d.ts +1 -1
  43. package/dist/presentation/index.js +2474 -2475
  44. package/dist/providers/index.d.ts +2 -2
  45. package/dist/providers/index.js +7 -7
  46. package/package.json +15 -15
@@ -10,18 +10,18 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
10
10
  import {
11
11
  createProvider,
12
12
  createProviderFromEnv,
13
- getAvailableProviders,
14
13
  DEFAULT_MODELS,
15
- MODELS,
16
- getModelsForProvider,
14
+ getAvailableProviders,
15
+ getDefaultModel,
16
+ getEnvVarName,
17
17
  getModelInfo,
18
+ getModelsForProvider,
18
19
  getRecommendedModels,
19
- getDefaultModel,
20
- validateProvider,
21
20
  hasCredentials,
22
- getEnvVarName,
23
21
  isOllamaRunning,
24
- listOllamaModels
22
+ listOllamaModels,
23
+ MODELS,
24
+ validateProvider
25
25
  } from "@contractspec/lib.ai-providers";
26
26
 
27
27
  // src/providers/chat-utilities.ts
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Workspace context for code-aware chat
3
3
  */
4
- export * from './workspace-context';
5
4
  export * from './context-builder';
6
5
  export * from './file-operations';
6
+ export * from './workspace-context';
@@ -1,99 +1,6 @@
1
1
  // @bun
2
2
  var __require = import.meta.require;
3
3
 
4
- // src/context/workspace-context.ts
5
- class WorkspaceContext {
6
- workspacePath;
7
- allowWrites;
8
- specs = [];
9
- files = [];
10
- initialized = false;
11
- constructor(config) {
12
- this.workspacePath = config.workspacePath;
13
- this.allowWrites = config.allowWrites ?? false;
14
- }
15
- async initialize() {
16
- if (this.initialized)
17
- return;
18
- this.initialized = true;
19
- }
20
- getSpecs() {
21
- return this.specs;
22
- }
23
- getFiles() {
24
- return this.files;
25
- }
26
- addSpecs(specs) {
27
- this.specs.push(...specs);
28
- }
29
- addFiles(files) {
30
- this.files.push(...files);
31
- }
32
- getSummary() {
33
- const commands = this.specs.filter((s) => s.type === "command").length;
34
- const queries = this.specs.filter((s) => s.type === "query").length;
35
- const events = this.specs.filter((s) => s.type === "event").length;
36
- const presentations = this.specs.filter((s) => s.type === "presentation").length;
37
- const tsFiles = this.files.filter((f) => f.extension === ".ts").length;
38
- const specFiles = this.files.filter((f) => f.isSpec).length;
39
- return {
40
- name: this.workspacePath.split("/").pop() ?? "workspace",
41
- path: this.workspacePath,
42
- specs: {
43
- total: this.specs.length,
44
- commands,
45
- queries,
46
- events,
47
- presentations
48
- },
49
- files: {
50
- total: this.files.length,
51
- typescript: tsFiles,
52
- specFiles
53
- }
54
- };
55
- }
56
- getContextSummary() {
57
- const summary = this.getSummary();
58
- const parts = [
59
- `Workspace: ${summary.name}`,
60
- `Path: ${summary.path}`,
61
- "",
62
- "### Specs",
63
- `- Commands: ${summary.specs.commands}`,
64
- `- Queries: ${summary.specs.queries}`,
65
- `- Events: ${summary.specs.events}`,
66
- `- Presentations: ${summary.specs.presentations}`
67
- ];
68
- if (this.specs.length > 0) {
69
- parts.push("", "### Available Specs");
70
- for (const spec of this.specs.slice(0, 20)) {
71
- parts.push(`- ${spec.name} (${spec.type})`);
72
- }
73
- if (this.specs.length > 20) {
74
- parts.push(`- ... and ${this.specs.length - 20} more`);
75
- }
76
- }
77
- return parts.join(`
78
- `);
79
- }
80
- findSpecs(query) {
81
- const lowerQuery = query.toLowerCase();
82
- return this.specs.filter((s) => s.name.toLowerCase().includes(lowerQuery) || s.description?.toLowerCase().includes(lowerQuery) || s.tags?.some((t) => t.toLowerCase().includes(lowerQuery)));
83
- }
84
- findFiles(query) {
85
- const lowerQuery = query.toLowerCase();
86
- return this.files.filter((f) => f.path.toLowerCase().includes(lowerQuery) || f.name.toLowerCase().includes(lowerQuery));
87
- }
88
- }
89
- async function createWorkspaceContext(path, options) {
90
- const context = new WorkspaceContext({
91
- workspacePath: path,
92
- ...options
93
- });
94
- await context.initialize();
95
- return context;
96
- }
97
4
  // src/context/context-builder.ts
98
5
  function estimateTokens(text) {
99
6
  return Math.ceil(text.length / 4);
@@ -400,6 +307,99 @@ function createNodeFileOperations(workspacePath, allowWrites = false) {
400
307
  };
401
308
  return new FileOperations(fs, workspacePath, allowWrites);
402
309
  }
310
+ // src/context/workspace-context.ts
311
+ class WorkspaceContext {
312
+ workspacePath;
313
+ allowWrites;
314
+ specs = [];
315
+ files = [];
316
+ initialized = false;
317
+ constructor(config) {
318
+ this.workspacePath = config.workspacePath;
319
+ this.allowWrites = config.allowWrites ?? false;
320
+ }
321
+ async initialize() {
322
+ if (this.initialized)
323
+ return;
324
+ this.initialized = true;
325
+ }
326
+ getSpecs() {
327
+ return this.specs;
328
+ }
329
+ getFiles() {
330
+ return this.files;
331
+ }
332
+ addSpecs(specs) {
333
+ this.specs.push(...specs);
334
+ }
335
+ addFiles(files) {
336
+ this.files.push(...files);
337
+ }
338
+ getSummary() {
339
+ const commands = this.specs.filter((s) => s.type === "command").length;
340
+ const queries = this.specs.filter((s) => s.type === "query").length;
341
+ const events = this.specs.filter((s) => s.type === "event").length;
342
+ const presentations = this.specs.filter((s) => s.type === "presentation").length;
343
+ const tsFiles = this.files.filter((f) => f.extension === ".ts").length;
344
+ const specFiles = this.files.filter((f) => f.isSpec).length;
345
+ return {
346
+ name: this.workspacePath.split("/").pop() ?? "workspace",
347
+ path: this.workspacePath,
348
+ specs: {
349
+ total: this.specs.length,
350
+ commands,
351
+ queries,
352
+ events,
353
+ presentations
354
+ },
355
+ files: {
356
+ total: this.files.length,
357
+ typescript: tsFiles,
358
+ specFiles
359
+ }
360
+ };
361
+ }
362
+ getContextSummary() {
363
+ const summary = this.getSummary();
364
+ const parts = [
365
+ `Workspace: ${summary.name}`,
366
+ `Path: ${summary.path}`,
367
+ "",
368
+ "### Specs",
369
+ `- Commands: ${summary.specs.commands}`,
370
+ `- Queries: ${summary.specs.queries}`,
371
+ `- Events: ${summary.specs.events}`,
372
+ `- Presentations: ${summary.specs.presentations}`
373
+ ];
374
+ if (this.specs.length > 0) {
375
+ parts.push("", "### Available Specs");
376
+ for (const spec of this.specs.slice(0, 20)) {
377
+ parts.push(`- ${spec.name} (${spec.type})`);
378
+ }
379
+ if (this.specs.length > 20) {
380
+ parts.push(`- ... and ${this.specs.length - 20} more`);
381
+ }
382
+ }
383
+ return parts.join(`
384
+ `);
385
+ }
386
+ findSpecs(query) {
387
+ const lowerQuery = query.toLowerCase();
388
+ return this.specs.filter((s) => s.name.toLowerCase().includes(lowerQuery) || s.description?.toLowerCase().includes(lowerQuery) || s.tags?.some((t) => t.toLowerCase().includes(lowerQuery)));
389
+ }
390
+ findFiles(query) {
391
+ const lowerQuery = query.toLowerCase();
392
+ return this.files.filter((f) => f.path.toLowerCase().includes(lowerQuery) || f.name.toLowerCase().includes(lowerQuery));
393
+ }
394
+ }
395
+ async function createWorkspaceContext(path, options) {
396
+ const context = new WorkspaceContext({
397
+ workspacePath: path,
398
+ ...options
399
+ });
400
+ await context.initialize();
401
+ return context;
402
+ }
403
403
  export {
404
404
  createWorkspaceContext,
405
405
  createNodeFileOperations,
@@ -2,8 +2,8 @@
2
2
  * Converts AgentToolConfig from ai-agent to AI SDK ToolSet.
3
3
  * Handlers are optional; when missing, execute returns unimplemented stub.
4
4
  */
5
- import { type ToolSet } from 'ai';
6
5
  import type { AgentToolConfig } from '@contractspec/lib.ai-agent';
6
+ import { type ToolSet } from 'ai';
7
7
  export type ToolHandler = (input: Record<string, unknown>) => Promise<unknown> | unknown;
8
8
  /**
9
9
  * Convert AgentToolConfig array to AI SDK ToolSet.
@@ -4,14 +4,14 @@
4
4
  import { type ToolSet } from 'ai';
5
5
  import type { Provider as ChatProvider } from '@contractspec/lib.ai-providers';
6
6
  import type { ModelSelector } from '@contractspec/lib.ai-providers/selector-types';
7
- import type { WorkflowComposer } from '@contractspec/lib.workflow-composer';
8
7
  import type { WorkflowSpec } from '@contractspec/lib.contracts-spec/workflow';
8
+ import type { ResolvedSurfacePlan } from '@contractspec/lib.surface-runtime/runtime/resolve-bundle';
9
+ import type { WorkflowComposer } from '@contractspec/lib.workflow-composer';
9
10
  import type { WorkspaceContext } from '../context/workspace-context';
10
- import type { ConversationStore } from './conversation-store';
11
- import { type ThinkingLevel } from './thinking-levels';
12
11
  import { type ContractsContextConfig } from './contracts-context';
13
- import type { ResolvedSurfacePlan } from '@contractspec/lib.surface-runtime/runtime/resolve-bundle';
12
+ import type { ConversationStore } from './conversation-store';
14
13
  import type { ChatConversation, ChatMessage, SendMessageOptions, SendMessageResult, StreamMessageResult } from './message-types';
14
+ import { type ThinkingLevel } from './thinking-levels';
15
15
  /**
16
16
  * Configuration for ChatService
17
17
  */
@@ -14,8 +14,8 @@
14
14
  * export const maxDuration = CHAT_ROUTE_MAX_DURATION;
15
15
  * ```
16
16
  */
17
- import { type LanguageModel, type ToolSet } from 'ai';
18
17
  import type { Provider as ChatProvider } from '@contractspec/lib.ai-providers';
18
+ import { type LanguageModel, type ToolSet } from 'ai';
19
19
  import type { ThinkingLevel } from './thinking-levels';
20
20
  /** Recommended maxDuration for Next.js route handlers (Vercel/serverless). */
21
21
  export declare const CHAT_ROUTE_MAX_DURATION = 30;
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Server route helper for AI SDK–compatible completion streaming.
3
+ *
4
+ * Use with @ai-sdk/react useCompletion for non-chat completion (inline suggestions, etc.).
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * // app/api/completion/route.ts (Next.js App Router)
9
+ * import { createCompletionRoute } from '@contractspec/module.ai-chat/core';
10
+ * import { createProvider } from '@contractspec/lib.ai-providers';
11
+ *
12
+ * const provider = createProvider({ provider: 'openai', apiKey: process.env.OPENAI_API_KEY });
13
+ * export const POST = createCompletionRoute({ provider });
14
+ * ```
15
+ */
1
16
  import type { Provider as ChatProvider } from '@contractspec/lib.ai-providers';
2
17
  export interface CreateCompletionRouteOptions {
3
18
  /** LLM provider (from createProvider) */
@@ -2,7 +2,7 @@
2
2
  * Export formatters for chat conversations
3
3
  * Pure functions to convert ChatMessage[] to Markdown, TXT, or JSON.
4
4
  */
5
- import type { ChatMessage, ChatConversation } from './message-types';
5
+ import type { ChatConversation, ChatMessage } from './message-types';
6
6
  /**
7
7
  * Format messages as Markdown
8
8
  */
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * Core chat functionality
3
3
  */
4
- export * from './message-types';
5
- export * from './conversation-store';
4
+ export * from './agent-adapter';
5
+ export * from './agent-tools-adapter';
6
6
  export * from './chat-service';
7
+ export * from './contracts-context';
8
+ export * from './conversation-store';
7
9
  export * from './create-chat-route';
8
10
  export * from './create-completion-route';
9
11
  export * from './export-formatters';
10
12
  export * from './local-storage-conversation-store';
13
+ export * from './message-types';
14
+ export * from './surface-planner-tools';
11
15
  export * from './thinking-levels';
12
16
  export * from './workflow-tools';
13
- export * from './contracts-context';
14
- export * from './agent-tools-adapter';
15
- export * from './surface-planner-tools';
16
- export * from './agent-adapter';